<? 
	include("seguranca.php");
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" type="text/css" media="all" href="style\css/style.css" />
<link rel="stylesheet" type="text/css" href="style/css/media-queries.css" />
<link rel="stylesheet" type="text/css" href="style/js/player/mediaelementplayer.css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,300italic,300,700,700italic|Open+Sans+Condensed:300,700' rel="stylesheet" type='text/css'>
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/css/ie8.css" media="all" />
<![endif]-->
<!--[if IE 9]>
<link rel="stylesheet" type="text/css" href="style/css/ie9.css" media="all" />
<![endif]-->
<script type="text/javascript" src="style/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="style/js/ddsmoothmenu.js"></script>
<script type="text/javascript" src="style/js/retina.js"></script>
<script type="text/javascript" src="style/js/selectnav.js"></script>
<script type="text/javascript" src="style/js/jquery.masonry.min.js"></script>
<script type="text/javascript" src="style/js/jquery.fitvids.js"></script>
<script type="text/javascript" src="style/js/jquery.backstretch.min.js"></script>
<script type="text/javascript" src="style/js/mediaelement.min.js"></script>
<script type="text/javascript" src="style/js/mediaelementplayer.min.js"></script>
<script type="text/javascript" src="style/js/jquery.dcflickr.1.0.js"></script>
<script type="text/javascript" src="style/js/twitter.min.js"></script>
<script type="text/javascript">
	$.backstretch("");
</script>
</head>
<body>

<div class="scanlines"></div>

<!-- Begin Header -->
<div class="header-wrapper opacity">
	<div class="header">
		<!-- Begin Logo -->
		<div class="logo">
		    <a href="index.html">
				<img src="style/images/logo_sem_fundo.png" alt="" />
			</a>
	    </div>
        
	    <h6>TAKON</h6>
		<!-- End Logo -->
		<!-- Begin logoff -->
		<div id="logoff-user">
			<div id="logoff" class="logoff">
            	<? 
				protegePagina();
				if($_SESSION['nivel'] != 'professor'){ //Se não for professor desloga o usuário e expulsa da página
					expulsaVisitante();
				}
				
				$nome = $_SESSION['usuarioNome']; 
				
				?>
				<h5>Olá <?php echo "{$nome}" ?> </h5>
				<a class="button blue" href="sair.php">logoff</a>
			</div>
		</div>
		<div class="clear"></div>
		<!-- End logoff -->

	</div>
</div>
<!-- End Header -->

<body>

 	<?
		include "config.php";
		# AUTORIZA
			if(isset($_GET['action']) && $_GET['action'] == 'autoriza'){
				$id = (int)$_GET['id'];

				$sqlAutoriza = 'UPDATE alunos SET verificado = 1 WHERE id = :id';

				try {
					$autoriza = $db->prepare($sqlAutoriza);
					$autoriza->bindValue(':id', $id, PDO::PARAM_INT);
					if($autoriza->execute()){
						echo "<div class='alert alert-success'>
						<button type='button' class='close' data-dismiss='alert'>&times;</button>
						<strong>Autorizado com sucesso!</strong>
						</div>";
					}
				} catch (PDOException $e) {
					echo "<div class='alert alert-error'>
						<button type='button' class='close' data-dismiss='alert'>&times;</button>
						<strong>Erro ao tentar autorizar!</strong>" . $e->getMessage() . "
						</div>";
				}
			}
		
		# DELETE
			if(isset($_GET['action']) && $_GET['action'] == 'delete'){
				$id = (int)$_GET['id'];

				$sqlDelete = 'DELETE FROM alunos WHERE id = :id';

				try {
					$delete = $db->prepare($sqlDelete);
					$delete->bindValue(':id', $id, PDO::PARAM_INT);
					if($delete->execute()){
						echo "<div class='alert alert-success'>
						<button type='button' class='close' data-dismiss='alert'>&times;</button>
						<strong>Deletado com sucesso!</strong>
						</div>";
					}
				} catch (PDOException $e) {
					echo "<div class='alert alert-error'>
						<button type='button' class='close' data-dismiss='alert'>&times;</button>
						<strong>Erro ao deletar dados!</strong>" . $e->getMessage() . "
						</div>";
				}
			}
	?>


<center>
  <a href="Mensagem.php" class="button sienna">Mensagens</a>
  <a href="atualizacao.php" class="button sandy">Atualizações</a>
  <a href="amizade.php" class="button purple">Solicitação de Amizade</a> 
</center>

<!-- Begin Blog Grid -->
<div class="blog-wrap">
	<!-- Begin Blog -->
	<div class="blog-grid">
		<!-- Begin Meus alunos -->

		<div class="post format-standard box">

			<h2 class="title"><a href="post.html">Meus Alunos</a></h2>
			<article>
            <section class="jumbotron">
                <table class="table table-hover">
                	<thead>
                            <tr>
                                <th>Nome:</th>
                                <th>Usuário:</th>
                                <th>Série:</th>
                            </tr>
                        </thead>
            			<tbody>
							<?
							$id = $_SESSION['usuarioID'];
                			$sql = $db->query("SELECT * FROM professores WHERE id = '$id'");
							$resultado = $sql->fetch(PDO::FETCH_ASSOC);
							$escola = $resultado['escola'];
                            $rs = $db->query("SELECT * FROM `alunos` WHERE verificado = 1 AND escola = '$escola' ORDER BY nome");
                            while ($linha = $rs->fetch(PDO::FETCH_ASSOC)) { ?>
                            <tr>
                                <td><h7><?php echo "{$linha['nome']}" ?></td>
                                <td><h7><?php echo "{$linha['usuario']}" ?></td>
                                <td><h7><?php echo "{$linha['serie']}" ?></td>
                                <td>
                                    <a href="professor.php?action=delete&id=<?php echo $linha['id']; ?>" class="btn" 
                                        onclick="return confirm('Deseja deletar?');"><i class="icon-remove"></i></a>
                                </td>
                            </tr>
							<?
                            } 
                            ?>
					 </tbody>
        		</table>
           </section>
           </article>
		</div>

		<!-- End Meus alunos -->


		<!-- Begin aguardando aprovação -->
	<div class="post format-standard box">
			<? include "config.php"; ?>
			<h2 class="title"><a href="post.html">Aceitar Aluno</a></h2>            
            <article>
            <section class="jumbotron">
                <table class="table table-hover">
                	<thead>
                            <tr>
                                <th>Nome:</th>
                                <th>Usuário:</th>
                                <th>E-mail:</th>
                                <th>Escola:</th>
                                <th>Série:</th>
                            </tr>
                        </thead>
            			<tbody>
							<?
							$id = $_SESSION['usuarioID'];
                			$sql = $db->query("SELECT * FROM professores WHERE id = '$id'");
							$resultado = $sql->fetch(PDO::FETCH_ASSOC);
							$escola = $resultado['escola'];
                            $rs = $db->query("SELECT * FROM `alunos` WHERE verificado = 0 AND escola = '$escola' ORDER BY nome");
                            while ($linha = $rs->fetch(PDO::FETCH_ASSOC)) { ?>
                            <tr>
                                <td><h7><?php echo "{$linha['nome']}" ?></td>
                                <td><h7><?php echo "{$linha['usuario']}" ?></td>
                                <td><h7><?php echo "{$linha['email']}" ?></td>
                                <td><h7><?php echo "{$linha['escola']}" ?></td>
                                <td><h7><?php echo "{$linha['serie']}" ?></td>
                                <td>
                                    <a href="professor.php?action=autoriza&id=<?php echo $linha['id']; ?>" class="btn" 
                                        onclick="return confirm('Deseja autorizar?');"><i class="icon-ok"></i></a>
                                    <a href="professor.php?action=delete&id=<?php echo $linha['id']; ?>" class="btn" 
                                        onclick="return confirm('Deseja deletar?');"><i class="icon-remove"></i></a>
                                </td>
                            </tr>
							<?
                            } 
                            ?>
					 </tbody>
        		</table>
           </section>
           </article>
		</div>
		<!-- End aguardando aprovação -->


		<!-- Begin Ranking-->
		<div class="post format-standard box">

			<h2 class="title"><a href="post.html">Ranking</a></h2>
			<p>Colocar o Ranking das salas que o professor criou </p>
		</div>

		</div>
		<!-- End Ranking -->


		<!-- Begin Salas -->

	  <div class="post format-standard box">

			<h2 class="title"><a href="post.html">Minhas Salas</a></h2>
			<p>Colocar os nomes das salas administradas pelo professor </p>
			<a class="button green">Criar nova sala</a>
			<a class="button yellow">Editar salas</a>
		</div>

		<!-- End Salas -->

 	</div>
	<!-- End Blog -->
</div>
<!-- End Blog Grid -->

</body>


<!-- Begin Footer -->
<div class="footer-wrapper">
<div id="footer" class="four">
		<div id="first" class="widget-area">
			<p><a href ="http://inf.unioeste.br/tesc/takon/quem_somos.html">Quem Somos</a></p>
			<p><a href = "http://inf.unioeste.br/tesc/takon/contato.html">Fale Conosco</a></p>
		</div><!-- #first .widget-area -->

	<div id="second" class="widget-area">
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Finf.unioeste.br%2Ftesc%2Ftakon%2F&amp;width&amp;layout=button_count&amp;action=like&amp;
show_faces=false&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
		</div><!-- #second .widget-area -->


		</div><!-- #third .widget-area -->


		</div><!-- #fourth .widget-area -->
	</div>
</div>
<div class="site-generator-wrapper">
	<div class="site-generator">Copyright Takon 2014. Design by Takon. All rights reserved.</div>
</div>

<!-- End Footer -->
<script type="text/javascript" src="style/js/scripts.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>